import mysql.connector
# ------------------------------连接数据库并建表------------------------------------------------------------------------
conn = mysql.connector.connect(user="root", password="root", database="yuanzheng")
#cur = conn.cursor()
#cur.execute("create table book(id varchar (20) primary key, name varchar (20), user_id varchar (20))")
#cur.execute("insert into book values (%s, %s, %s)", ("01", "《果核中的宇宙》", "0001"))
#cur.execute("insert into book values (%s, %s, %s)", ("02", "《Java从入门到精通》", "0001"))
#print(cur.rowcount)
#conn.commit()
#cur.close()
# ------------------------------连接查看数据库--------------------------------------------------------------------------
cur2 = conn.cursor()
cur2.execute("select * from book")
print(cur2.fetchall())
cur2.close()
conn.close()
